home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / COMPOBJ.H < prev    next >
C/C++ Source or Header  |  1993-11-16  |  35KB  |  1,032 lines

  1. /*****************************************************************************\
  2. *                                                                             *
  3. * compobj.h -     Component object model definitions                              *
  4. *                                                                             *
  5. *               OLE Version 2.0                                               *
  6. *                                                                             *
  7. *               Copyright (c) 1992-1993, Microsoft Corp. All rights reserved. *
  8. *                                                                             *
  9. \*****************************************************************************/
  10.  
  11.  
  12. #if !defined( _COMPOBJ_H_ )
  13. #define _COMPOBJ_H_
  14.  
  15. /****** Linkage Definitions *************************************************/
  16.  
  17. /*
  18.  *      These are macros for declaring methods/functions.  They exist so that
  19.  *      control over the use of keywords (CDECL, PASCAL, __export,
  20.  *      extern "C") resides in one place, and because this is the least
  21.  *      intrusive way of writing function declarations that do not have
  22.  *      to be modified in order to port to the Mac.
  23.  *
  24.  *      The macros without the trailing underscore are for functions/methods
  25.  *      which a return value of type HRESULT; this is by far the most common
  26.  *      case in OLE. The macros with a trailing underscore take a return
  27.  *      type as a parameter.
  28.  *
  29.  * WARNING: STDAPI is hard coded into the LPFNGETCLASSOBJECT typedef below.
  30.  */
  31.  
  32. #ifdef __cplusplus
  33.     #define EXTERN_C    extern "C"
  34. #else
  35.     #define EXTERN_C    extern
  36. #endif
  37.  
  38. #ifdef _MAC
  39. #define STDMETHODCALLTYPE
  40. #define STDAPICALLTYPE          pascal
  41.  
  42. #define STDAPI                  EXTERN_C STDAPICALLTYPE HRESULT
  43. #define STDAPI_(type)           EXTERN_C STDAPICALLTYPE type
  44.  
  45. #else   //  !_MAC
  46.  
  47. #ifdef WIN32
  48. #define STDMETHODCALLTYPE       __export __cdecl
  49. #define STDAPICALLTYPE          __export __stdcall
  50.  
  51. #define STDAPI                  EXTERN_C HRESULT STDAPICALLTYPE
  52. #define STDAPI_(type)           EXTERN_C type STDAPICALLTYPE
  53.  
  54. #else
  55. #define STDMETHODCALLTYPE       __export FAR CDECL
  56. #define STDAPICALLTYPE          __export FAR PASCAL
  57.  
  58. #define STDAPI                  EXTERN_C HRESULT STDAPICALLTYPE
  59. #define STDAPI_(type)           EXTERN_C type STDAPICALLTYPE
  60.  
  61. #endif
  62.  
  63. #endif //!_MAC
  64.  
  65. #define STDMETHODIMP            HRESULT STDMETHODCALLTYPE
  66. #define STDMETHODIMP_(type)     type STDMETHODCALLTYPE
  67.  
  68.  
  69. /****** Interface Declaration ***********************************************/
  70.  
  71. /*
  72.  *      These are macros for declaring interfaces.  They exist so that
  73.  *      a single definition of the interface is simulataneously a proper
  74.  *      declaration of the interface structures (C++ abstract classes)
  75.  *      for both C and C++.
  76.  *
  77.  *      DECLARE_INTERFACE(iface) is used to declare an interface that does
  78.  *      not derive from a base interface.
  79.  *      DECLARE_INTERFACE_(iface, baseiface) is used to declare an interface
  80.  *      that does derive from a base interface.
  81.  *
  82.  *      By default if the source file has a .c extension the C version of
  83.  *      the interface declaratations will be expanded; if it has a .cpp
  84.  *      extension the C++ version will be expanded. if you want to force
  85.  *      the C version expansion even though the source file has a .cpp
  86.  *      extension, then define the macro "CINTERFACE".
  87.  *      eg.     cl -DCINTERFACE file.cpp
  88.  *
  89.  *      Example Interface declaration:
  90.  *
  91.  *          #undef  INTERFACE
  92.  *          #define INTERFACE   IClassFactory
  93.  *
  94.  *          DECLARE_INTERFACE_(IClassFactory, IUnknown)
  95.  *          {
  96.  *              // *** IUnknown methods ***
  97.  *              STDMETHOD(QueryInterface) (THIS_
  98.  *                                        REFIID riid,
  99.  *                                        LPVOID FAR* ppvObj) PURE;
  100.  *              STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  101.  *              STDMETHOD_(ULONG,Release) (THIS) PURE;
  102.  *
  103.  *              // *** IClassFactory methods ***
  104.  *              STDMETHOD(CreateInstance) (THIS_
  105.  *                                        LPUNKNOWN pUnkOuter,
  106.  *                                        REFIID riid,
  107.  *                                        LPVOID FAR* ppvObject) PURE;
  108.  *          };
  109.  *
  110.  *      Example C++ expansion:
  111.  *
  112.  *          struct FAR IClassFactory : public IUnknown
  113.  *          {
  114.  *              virtual HRESULT STDMETHODCALLTYPE QueryInterface(
  115.  *                                                  IID FAR& riid,
  116.  *                                                  LPVOID FAR* ppvObj) = 0;
  117.  *              virtual HRESULT STDMETHODCALLTYPE AddRef(void) = 0;
  118.  *              virtual HRESULT STDMETHODCALLTYPE Release(void) = 0;
  119.  *              virtual HRESULT STDMETHODCALLTYPE CreateInstance(
  120.  *                                              LPUNKNOWN pUnkOuter,
  121.  *                                              IID FAR& riid,
  122.  *                                              LPVOID FAR* ppvObject) = 0;
  123.  *          };
  124.  *
  125.  *          NOTE: Our documentation says '#define interface class' but we use
  126.  *          'struct' instead of 'class' to keep a lot of 'public:' lines
  127.  *          out of the interfaces.  The 'FAR' forces the 'this' pointers to
  128.  *          be far, which is what we need.
  129.  *
  130.  *      Example C expansion:
  131.  *
  132.  *          typedef struct IClassFactory
  133.  *          {
  134.  *              const struct IClassFactoryVtbl FAR* lpVtbl;
  135.  *          } IClassFactory;
  136.  *
  137.  *          typedef struct IClassFactoryVtbl IClassFactoryVtbl;
  138.  *
  139.  *          struct IClassFactoryVtbl
  140.  *          {
  141.  *              HRESULT (STDMETHODCALLTYPE * QueryInterface) (
  142.  *                                                  IClassFactory FAR* This,
  143.  *                                                  IID FAR* riid,
  144.  *                                                  LPVOID FAR* ppvObj) ;
  145.  *              HRESULT (STDMETHODCALLTYPE * AddRef) (IClassFactory FAR* This) ;
  146.  *              HRESULT (STDMETHODCALLTYPE * Release) (IClassFactory FAR* This) ;
  147.  *              HRESULT (STDMETHODCALLTYPE * CreateInstance) (
  148.  *                                                  IClassFactory FAR* This,
  149.  *                                                  LPUNKNOWN pUnkOuter,
  150.  *                                                  IID FAR* riid,
  151.  *                                                  LPVOID FAR* ppvObject);
  152.  *              HRESULT (STDMETHODCALLTYPE * LockServer) (
  153.  *                                                  IClassFactory FAR* This,
  154.  *                                                  BOOL fLock);
  155.  *          };
  156.  */
  157.  
  158.  
  159. #if defined(__cplusplus) && !defined(CINTERFACE)
  160. #ifdef __TURBOC__
  161. #define interface               struct huge
  162. #else
  163. #define interface               struct FAR
  164. #endif
  165. #define STDMETHOD(method)       virtual HRESULT STDMETHODCALLTYPE method
  166. #define STDMETHOD_(type,method) virtual type STDMETHODCALLTYPE method
  167. #define PURE                    = 0
  168. #define THIS_
  169. #define THIS                    void
  170. #define DECLARE_INTERFACE(iface)    interface iface
  171. #define DECLARE_INTERFACE_(iface, baseiface)    interface iface : public baseiface
  172.  
  173. #else
  174. #define interface               struct
  175.  
  176. #ifdef _MAC
  177.  
  178. #define STDMETHOD(method)       long    method##pad;\
  179.                                 HRESULT (STDMETHODCALLTYPE * method)
  180. #define STDMETHOD_(type,method) long    method##pad;\
  181.                                 type (STDMETHODCALLTYPE * method)
  182.  
  183. #else // _MAC
  184.  
  185. #define STDMETHOD(method)       HRESULT (STDMETHODCALLTYPE * method)
  186. #define STDMETHOD_(type,method) type (STDMETHODCALLTYPE * method)
  187.  
  188. #endif // !_MAC
  189.  
  190. #define PURE
  191. #define THIS_                   INTERFACE FAR* This,
  192. #define THIS                    INTERFACE FAR* This
  193. #ifdef CONST_VTABLE
  194. #define DECLARE_INTERFACE(iface)    typedef interface iface { \
  195.                                     const struct iface##Vtbl FAR* lpVtbl; \
  196.                                 } iface; \
  197.                                 typedef const struct iface##Vtbl iface##Vtbl; \
  198.                                 const struct iface##Vtbl
  199. #else
  200. #define DECLARE_INTERFACE(iface)    typedef interface iface { \
  201.                                     struct iface##Vtbl FAR* lpVtbl; \
  202.                                 } iface; \
  203.                                 typedef struct iface##Vtbl iface##Vtbl; \
  204.                                 struct iface##Vtbl
  205. #endif
  206. #define DECLARE_INTERFACE_(iface, baseiface)    DECLARE_INTERFACE(iface)
  207.  
  208. #endif
  209.  
  210.  
  211. /****** Additional basic types **********************************************/
  212.  
  213.  
  214. #ifndef FARSTRUCT
  215. #ifdef __cplusplus
  216. #define FARSTRUCT   FAR
  217. #else
  218. #define FARSTRUCT   
  219. #endif  // __cplusplus
  220. #endif  // FARSTRUCT
  221.  
  222.  
  223. #ifndef WINAPI          /* If not included with 3.1 headers... */
  224.  
  225. #ifdef WIN32
  226. #define FAR
  227. #define PASCAL          __stdcall
  228. #define CDECL
  229. #else
  230. #define FAR             _far
  231. #define PASCAL          _pascal
  232. #define CDECL           _cdecl
  233. #endif
  234.  
  235. #define VOID            void
  236. #define WINAPI      FAR PASCAL
  237. #define CALLBACK    FAR PASCAL
  238.  
  239. #ifndef FALSE
  240. #define FALSE 0
  241. #define TRUE 1
  242. #endif
  243.  
  244. typedef int BOOL;
  245. typedef unsigned char BYTE;
  246. typedef unsigned short WORD;
  247. typedef unsigned int UINT;
  248.  
  249. typedef long LONG;
  250. typedef unsigned long DWORD;
  251.  
  252.  
  253. typedef UINT WPARAM;
  254. typedef LONG LPARAM;
  255. typedef LONG LRESULT;
  256.  
  257. typedef unsigned int HANDLE;
  258. #define DECLARE_HANDLE(name)    typedef UINT name
  259.  
  260. DECLARE_HANDLE(HMODULE);
  261. DECLARE_HANDLE(HINSTANCE);
  262. DECLARE_HANDLE(HLOCAL);
  263. DECLARE_HANDLE(HGLOBAL);
  264. DECLARE_HANDLE(HDC);
  265. DECLARE_HANDLE(HRGN);
  266. DECLARE_HANDLE(HWND);
  267. DECLARE_HANDLE(HMENU);
  268. DECLARE_HANDLE(HACCEL);
  269. DECLARE_HANDLE(HTASK);
  270.  
  271. #ifndef NULL
  272. #define NULL 0
  273. #endif
  274.  
  275.  
  276. typedef void FAR *      LPVOID;
  277. typedef WORD FAR *      LPWORD;
  278. typedef DWORD FAR *     LPDWORD;
  279. typedef char FAR*       LPSTR;
  280. typedef const char FAR* LPCSTR;
  281. typedef void FAR*       LPLOGPALETTE;
  282. typedef void FAR*       LPMSG;
  283. //typedef struct tagMSG FAR *LPMSG;
  284.  
  285. typedef HANDLE FAR *LPHANDLE;
  286. typedef struct tagRECT FAR *LPRECT;
  287.  
  288. typedef struct FARSTRUCT tagSIZE
  289. {
  290.     int cx;
  291.     int cy;
  292. } SIZE;
  293. typedef SIZE*       PSIZE;
  294.  
  295.  
  296. #endif  /* WINAPI */
  297.  
  298.  
  299. typedef short SHORT;
  300. typedef unsigned short USHORT;
  301. typedef DWORD ULONG;
  302.  
  303.  
  304. #ifndef HUGEP
  305. #ifdef WIN32
  306. #define HUGEP
  307. #else
  308. #define HUGEP __huge
  309. #endif // WIN32
  310. #endif // HUGEP
  311.  
  312. typedef WORD WCHAR;
  313.  
  314. #ifndef WIN32
  315. typedef struct FARSTRUCT _LARGE_INTEGER {
  316.     DWORD LowPart;
  317.     LONG  HighPart;
  318. } LARGE_INTEGER, *PLARGE_INTEGER;
  319. #endif
  320. #define LISet32(li, v) ((li).HighPart = ((LONG)(v)) < 0 ? -1 : 0, (li).LowPart = (v))
  321.  
  322. #ifndef WIN32
  323. typedef struct FARSTRUCT _ULARGE_INTEGER {
  324.     DWORD LowPart;
  325.     DWORD HighPart;
  326. } ULARGE_INTEGER, *PULARGE_INTEGER;
  327. #endif
  328. #define ULISet32(li, v) ((li).HighPart = 0, (li).LowPart = (v))
  329.  
  330. #ifndef _WINDOWS_
  331. #ifndef _FILETIME_
  332. #define _FILETIME_
  333. typedef struct FARSTRUCT tagFILETIME
  334. {
  335.     DWORD dwLowDateTime;
  336.     DWORD dwHighDateTime;
  337. } FILETIME;
  338. #endif
  339. #endif
  340.  
  341. #ifdef WIN32
  342. #define HTASK DWORD
  343. #endif
  344.  
  345. #include "scode.h"
  346.  
  347.  
  348.  
  349. // *********************** Compobj errors **********************************
  350.  
  351. #define CO_E_NOTINITIALIZED         (CO_E_FIRST + 0x0)
  352. // CoInitialize has not been called and must be
  353.  
  354. #define CO_E_ALREADYINITIALIZED     (CO_E_FIRST + 0x1)
  355. // CoInitialize has already been called and cannot be called again (temporary)
  356.  
  357. #define CO_E_CANTDETERMINECLASS     (CO_E_FIRST + 0x2)
  358. // can't determine clsid (e.g., extension not in reg.dat)
  359.  
  360. #define CO_E_CLASSSTRING            (CO_E_FIRST + 0x3)
  361. // the string form of the clsid is invalid (including ole1 classes)
  362.  
  363. #define CO_E_IIDSTRING              (CO_E_FIRST + 0x4)
  364. // the string form of the iid is invalid
  365.  
  366. #define CO_E_APPNOTFOUND            (CO_E_FIRST + 0x5)
  367. // application not found
  368.  
  369. #define CO_E_APPSINGLEUSE           (CO_E_FIRST + 0x6)
  370. // application cannot be run more than once
  371.  
  372. #define CO_E_ERRORINAPP             (CO_E_FIRST + 0x7)
  373. // some error in the app program file
  374.  
  375. #define CO_E_DLLNOTFOUND            (CO_E_FIRST + 0x8)
  376. // dll not found
  377.  
  378. #define CO_E_ERRORINDLL             (CO_E_FIRST + 0x9)
  379. // some error in the dll file
  380.  
  381. #define CO_E_WRONGOSFORAPP          (CO_E_FIRST + 0xa)
  382. // app written for other version of OS or other OS altogether
  383.  
  384. #define CO_E_OBJNOTREG              (CO_E_FIRST + 0xb)
  385. // object is not registered
  386.  
  387. #define CO_E_OBJISREG               (CO_E_FIRST + 0xc)
  388. // object is already registered
  389.  
  390. #define CO_E_OBJNOTCONNECTED        (CO_E_FIRST + 0xd)
  391. // handler is not connected to server
  392.  
  393. #define CO_E_APPDIDNTREG            (CO_E_FIRST + 0xe)
  394. // app was launched, but didn't registered a class factory
  395.  
  396.  
  397. // ********************* ClassObject errors ********************************
  398.  
  399. #define CLASS_E_NOAGGREGATION       (CLASSFACTORY_E_FIRST + 0x0)
  400. // class does not support aggregation (or class object is remote)
  401.  
  402. #define CLASS_E_CLASSNOTAVAILABLE   (CLASSFACTORY_E_FIRST + 0x1)
  403. // dll doesn't support that class (returned from DllGetClassObject)
  404.  
  405.  
  406. // *********************** Reg.dat errors **********************************
  407.  
  408. #define REGDB_E_READREGDB           (REGDB_E_FIRST + 0x0)
  409. // some error reading the registration database
  410.  
  411. #define REGDB_E_WRITEREGDB          (REGDB_E_FIRST + 0x1)
  412. // some error reading the registration database
  413.  
  414. #define REGDB_E_KEYMISSING          (REGDB_E_FIRST + 0x2)
  415. // some error reading the registration database
  416.  
  417. #define REGDB_E_INVALIDVALUE        (REGDB_E_FIRST + 0x3)
  418. // some error reading the registration database
  419.  
  420. #define REGDB_E_CLASSNOTREG         (REGDB_E_FIRST + 0x4)
  421. // some error reading the registration database
  422.  
  423. #define REGDB_E_IIDNOTREG           (REGDB_E_FIRST + 0x5)
  424. // some error reading the registration database
  425.  
  426.  
  427. // *************************** RPC errors **********************************
  428.  
  429. #define RPC_E_FIRST    MAKE_SCODE(SEVERITY_ERROR, FACILITY_RPC,  0x000)
  430.  
  431. // call was rejected by callee, either by MF::HandleIncomingCall or
  432. #define RPC_E_CALL_REJECTED             (RPC_E_FIRST + 0x1)         
  433.  
  434. // call was canceld by call - returned by MessagePending
  435. // this code only occurs if MessagePending return cancel
  436. #define RPC_E_CALL_CANCELED             (RPC_E_FIRST + 0x2)         
  437.  
  438. // the caller is dispatching an intertask SendMessage call and 
  439. // can NOT call out via PostMessage
  440. #define RPC_E_CANTPOST_INSENDCALL       (RPC_E_FIRST + 0x3)             
  441.  
  442. // the caller is dispatching an asynchronus call can NOT 
  443. // make an outgoing call on behalf of this call
  444. #define RPC_E_CANTCALLOUT_INASYNCCALL   (RPC_E_FIRST + 0x4)         
  445.  
  446. // the caller is not in a state where an outgoing call can be made
  447. // this is the case if the caller has an outstandig call and
  448. // another incoming call was excepted by HIC; now the caller is
  449. // not allowed to call out again
  450. #define RPC_E_CANTCALLOUT_INEXTERNALCALL (RPC_E_FIRST + 0x5)                
  451.  
  452. // the connection terminated or is in a bogus state
  453. // and can not be used any more. Other connections
  454. // are still valid.
  455. #define RPC_E_CONNECTION_TERMINATED     (RPC_E_FIRST + 0x6)         
  456.  
  457. // the callee (server [not server application]) is not available 
  458. // and disappeared; all connections are invalid
  459. #define RPC_E_SERVER_DIED               (RPC_E_FIRST + 0x7)         
  460.  
  461. // the caller (client ) disappeared while the callee (server) was 
  462. // processing a call 
  463. #define RPC_E_CLIENT_DIED               (RPC_E_FIRST + 0x8)         
  464.  
  465. // the date paket with the marshalled parameter data is
  466. // incorrect 
  467. #define RPC_E_INVALID_DATAPACKET        (RPC_E_FIRST + 0x9)         
  468.  
  469. // the call was not transmitted properly; the message queue 
  470. // was full and was not emptied after yielding
  471. #define RPC_E_CANTTRANSMIT_CALL         (RPC_E_FIRST + 0xa)         
  472.  
  473. // the client (caller) can not marshall the parameter data 
  474. // or unmarshall the return data - low memory etc.
  475. #define RPC_E_CLIENT_CANTMARSHAL_DATA   (RPC_E_FIRST + 0xb)         
  476. #define RPC_E_CLIENT_CANTUNMARSHAL_DATA (RPC_E_FIRST + 0xc)         
  477.  
  478. // the server (caller) can not unmarshall the parameter data
  479. // or marshall the return data - low memory
  480. #define RPC_E_SERVER_CANTMARSHAL_DATA   (RPC_E_FIRST + 0xd)         
  481. #define RPC_E_SERVER_CANTUNMARSHAL_DATA (RPC_E_FIRST + 0xe)         
  482.  
  483. // received data are invalid; can be server or 
  484. // client data
  485. #define RPC_E_INVALID_DATA              (RPC_E_FIRST + 0xf)         
  486.  
  487. // a particular parameter is invalid and can not be un/marshalled
  488. #define RPC_E_INVALID_PARAMETER         (RPC_E_FIRST + 0x10)
  489.  
  490. // DDE conversation - no second outgoing call on same channel
  491. #define RPC_E_CANTCALLOUT_AGAIN            (RPC_E_FIRST + 0x11)         
  492.  
  493. // a internal error occured 
  494. #define RPC_E_UNEXPECTED                (RPC_E_FIRST + 0xFFFF)
  495.  
  496.  
  497. /****** Globally Unique Ids *************************************************/
  498.  
  499. #ifdef __cplusplus
  500.  
  501. struct FAR GUID
  502. {
  503.     DWORD Data1;
  504.     WORD  Data2;
  505.     WORD  Data3;
  506.     BYTE  Data4[8];
  507.  
  508.     BOOL operator==(const GUID& iidOther) const
  509.  
  510. #ifdef WIN32
  511.         { return !memcmp(&Data1,&iidOther.Data1,sizeof(GUID)); }
  512. #else        
  513.         { return !_fmemcmp(&Data1,&iidOther.Data1,sizeof(GUID)); }
  514. #endif
  515.     BOOL operator!=(const GUID& iidOther) const
  516.         { return !((*this) == iidOther); }
  517. };
  518.  
  519. #else
  520. typedef struct GUID
  521. {
  522.     DWORD Data1;
  523.     WORD  Data2;
  524.     WORD  Data3;
  525.     BYTE  Data4[8];
  526. } GUID;
  527. #endif
  528.  
  529. typedef                GUID FAR* LPGUID;
  530.  
  531.  
  532. // macros to define byte pattern for a GUID.  
  533. //      Example: DEFINE_GUID(GUID_XXX, a, b, c, ...);
  534. //
  535. // Each dll/exe must initialize the GUIDs once.  This is done in one of
  536. // two ways.  If you are not using precompiled headers for the file(s) which
  537. // initializes the GUIDs, define INITGUID before including compobj.h.  This
  538. // is how OLE builds the initialized versions of the GUIDs which are included
  539. // in compobj.dll.
  540. //
  541. // The alternative (which some versions of the compiler don't handle properly;
  542. // they wind up with the initialized GUIDs in a data, not a text segment),
  543. // is to use a precompiled version of compobj.h and then include initguid.h 
  544. // after compobj.h followed by one or more of the guid defintion files.
  545.  
  546.  
  547. #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
  548.     EXTERN_C const GUID CDECL FAR name
  549.  
  550. #ifdef INITGUID
  551. #include "initguid.h"
  552. #endif
  553.  
  554. #define DEFINE_OLEGUID(name, l, w1, w2) \
  555.     DEFINE_GUID(name, l, w1, w2, 0xC0,0,0,0,0,0,0,0x46)
  556.  
  557.  
  558. // Interface ID are just a kind of GUID
  559. typedef GUID IID;
  560. typedef                IID FAR* LPIID;
  561. #define IID_NULL            GUID_NULL
  562. #define IsEqualIID(riid1, riid2) IsEqualGUID(riid1, riid2)
  563.  
  564.  
  565. // Class ID are just a kind of GUID
  566. typedef GUID CLSID;
  567. typedef              CLSID FAR* LPCLSID;
  568. #define CLSID_NULL          GUID_NULL
  569. #define IsEqualCLSID(rclsid1, rclsid2) IsEqualGUID(rclsid1, rclsid2)
  570.  
  571.  
  572. #if defined(__cplusplus)
  573. #define REFGUID             const GUID FAR&
  574. #define REFIID              const IID FAR&
  575. #define REFCLSID            const CLSID FAR&
  576. #else
  577. #define REFGUID             const GUID FAR* const
  578. #define REFIID              const IID FAR* const
  579. #define REFCLSID            const CLSID FAR* const
  580. #endif
  581.  
  582.  
  583. #ifndef INITGUID
  584. #include "coguid.h"
  585. #endif
  586.  
  587. /****** Other value types ***************************************************/
  588.  
  589. // memory context values; passed to CoGetMalloc
  590. typedef enum tagMEMCTX
  591. {
  592.     MEMCTX_TASK = 1,            // task (private) memory
  593.     MEMCTX_SHARED = 2,          // shared memory (between processes)
  594. #ifdef _MAC
  595.     MEMCTX_MACSYSTEM = 3,       // on the mac, the system heap
  596. #endif 
  597.  
  598.     // these are mostly for internal use...
  599.     MEMCTX_UNKNOWN = -1,        // unknown context (when asked about it)
  600.     MEMCTX_SAME = -2,           // same context (as some other pointer)
  601. } MEMCTX;
  602.  
  603.  
  604.  
  605. // class context: used to determine what scope and kind of class object to use
  606. // NOTE: this is a bitwise enum
  607. typedef enum tagCLSCTX
  608. {
  609.     CLSCTX_INPROC_SERVER = 1,   // server dll (runs in same process as caller)
  610.     CLSCTX_INPROC_HANDLER = 2,  // handler dll (runs in same process as caller)
  611.     CLSCTX_LOCAL_SERVER = 4     // server exe (runs on same machine; diff proc)
  612. } CLSCTX;
  613.  
  614. #define CLSCTX_ALL              (CLSCTX_INPROC_SERVER| \
  615.                                  CLSCTX_INPROC_HANDLER| \
  616.                                  CLSCTX_LOCAL_SERVER)
  617.  
  618. #define CLSCTX_INPROC           (CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER)
  619.  
  620. #define CLSCTX_SERVER           (CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER)
  621.  
  622.  
  623. // class registration flags; passed to CoRegisterClassObject
  624. typedef enum tagREGCLS
  625. {
  626.     REGCLS_SINGLEUSE = 0,       // class object only generates one instance
  627.     REGCLS_MULTIPLEUSE = 1,     // same class object genereates multiple inst.
  628.                                 // and local automatically goes into inproc tbl.
  629.     REGCLS_MULTI_SEPARATE = 2,  // multiple use, but separate control over each
  630.                                 // context.
  631.  
  632.     // NOTE: CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE is the same as
  633.     // (CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER), REGCLS_MULTI_SEPARATE, but
  634.     // not the same as CLSCTX_LOCAL_SERVER, REGCLS_MULTI_SEPARATE.
  635. } REGCLS;
  636.  
  637.  
  638. // interface marshaling definitions
  639. #define MARSHALINTERFACE_MIN 40 // minimum number of bytes for interface marshl
  640.  
  641. // marshaling flags; passed to CoMarshalInterface
  642. typedef enum tagMSHLFLAGS
  643. {
  644.     MSHLFLAGS_NORMAL = 0,       // normal marshaling via proxy/stub
  645.     MSHLFLAGS_TABLESTRONG = 1,  // keep object alive; must explicitly release
  646.     MSHLFLAGS_TABLEWEAK = 2     // doesn't hold object alive; still must release
  647. } MSHLFLAGS;
  648.  
  649. // marshal context: determines the destination context of the marshal operation
  650. typedef enum tagMSHCTX
  651. {
  652.     MSHCTX_LOCAL = 0,           // unmarshal context is local (eg.shared memory)
  653.     MSHCTX_NOSHAREDMEM = 1,     // unmarshal context has no shared memory access
  654. } MSHCTX;
  655.  
  656.  
  657. // call type used by IMessageFilter::HandleIncommingMessage
  658. typedef enum tagCALLTYPE
  659. {
  660.     CALLTYPE_TOPLEVEL = 1,      // toplevel call - no outgoing call 
  661.     CALLTYPE_NESTED   = 2,      // callback on behalf of previous outgoing call - should always handle
  662.     CALLTYPE_ASYNC    = 3,      // aysnchronous call - can NOT be rejected
  663.     CALLTYPE_TOPLEVEL_CALLPENDING = 4,  // new toplevel call with new LID
  664.     CALLTYPE_ASYNC_CALLPENDING    = 5   // async call - can NOT be rejected
  665. } CALLTYPE;
  666.  
  667. typedef struct tagINTERFACEINFO 
  668. {               
  669.     interface IUnknown FAR *pUnk;       // the pointer to the object
  670.     IID                  iid;            // interface id
  671.     WORD                wMethod;        // interface methode
  672. } INTERFACEINFO, FAR * LPINTERFACEINFO;
  673.  
  674. // status of server call - returned by IMessageFilter::HandleIncommingCall
  675. // and passed to  IMessageFilter::RetryRejectedCall
  676. typedef enum tagSERVERCALL
  677. {
  678.     SERVERCALL_ISHANDLED    = 0,
  679.     SERVERCALL_REJECTED     = 1,
  680.     SERVERCALL_RETRYLATER   = 2         
  681. } SERVERCALL;
  682.  
  683.  
  684. // Pending type indicates the level of nesting
  685. typedef enum tagPENDINGTYPE
  686. {   
  687.     PENDINGTYPE_TOPLEVEL = 1,       // toplevel call
  688.     PENDINGTYPE_NESTED   = 2,       // nested call
  689. } PENDINGTYPE;
  690.  
  691. // return values of MessagePending
  692. typedef enum tagPENDINGMSG
  693. {   
  694.     PENDINGMSG_CANCELCALL  = 0, // cancel the outgoing call
  695.     PENDINGMSG_WAITNOPROCESS  = 1, // wait for the return and don't dispatch the message
  696.     PENDINGMSG_WAITDEFPROCESS = 2  // wait and dispatch the message 
  697.     
  698. } PENDINGMSG;
  699.  
  700.  
  701. // bit flags for IExternalConnection
  702. typedef enum tagEXTCONN 
  703. {
  704.     EXTCONN_STRONG        = 0x0001    // strong connection
  705. } EXTCONN;
  706.  
  707.  
  708. /****** IUnknown Interface **************************************************/
  709.  
  710.  
  711. #undef  INTERFACE
  712. #define INTERFACE   IUnknown
  713.  
  714. DECLARE_INTERFACE(IUnknown)
  715. {
  716.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  717.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  718.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  719. };
  720.  
  721. typedef        IUnknown FAR* LPUNKNOWN;
  722.  
  723.  
  724. /****** Class Factory Interface *******************************************/
  725.  
  726.  
  727. #undef  INTERFACE
  728. #define INTERFACE   IClassFactory
  729.  
  730. DECLARE_INTERFACE_(IClassFactory, IUnknown)
  731. {
  732.     // *** IUnknown methods ***
  733.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  734.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  735.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  736.  
  737.     // *** IClassFactory methods ***
  738.     STDMETHOD(CreateInstance) (THIS_ LPUNKNOWN pUnkOuter,
  739.                               REFIID riid,
  740.                               LPVOID FAR* ppvObject) PURE;
  741.     STDMETHOD(LockServer) (THIS_ BOOL fLock) PURE;
  742.  
  743. };
  744. typedef       IClassFactory FAR* LPCLASSFACTORY;
  745.  
  746.  
  747. /****** Memory Allocation Interface ***************************************/
  748.  
  749.  
  750. #undef  INTERFACE
  751. #define INTERFACE   IMalloc
  752.  
  753. DECLARE_INTERFACE_(IMalloc, IUnknown)
  754. {
  755.     // *** IUnknown methods ***
  756.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  757.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  758.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  759.  
  760.     // *** IMalloc methods ***
  761.     STDMETHOD_(void FAR*, Alloc) (THIS_ ULONG cb) PURE;
  762.     STDMETHOD_(void FAR*, Realloc) (THIS_ void FAR* pv, ULONG cb) PURE;
  763.     STDMETHOD_(void, Free) (THIS_ void FAR* pv) PURE;
  764.     STDMETHOD_(ULONG, GetSize) (THIS_ void FAR* pv) PURE;
  765.     STDMETHOD_(int, DidAlloc) (THIS_ void FAR* pv) PURE;
  766.     STDMETHOD_(void, HeapMinimize) (THIS) PURE;
  767. };
  768. typedef       IMalloc FAR* LPMALLOC;
  769.  
  770.  
  771. /****** IMarshal Interface ************************************************/
  772.  
  773. // forward declaration for IStream; must include storage.h later to use
  774. #ifdef __cplusplus
  775. interface IStream;
  776. #else
  777. typedef interface IStream IStream;
  778. #endif
  779. typedef         IStream FAR* LPSTREAM;
  780.  
  781.  
  782. #undef  INTERFACE
  783. #define INTERFACE   IMarshal
  784.  
  785. DECLARE_INTERFACE_(IMarshal, IUnknown)
  786. {
  787.     // *** IUnknown methods ***
  788.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  789.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  790.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  791.  
  792.     // *** IMarshal methods ***
  793.     STDMETHOD(GetUnmarshalClass)(THIS_ REFIID riid, LPVOID pv, 
  794.                         DWORD dwDestContext, LPVOID pvDestContext,
  795.                         DWORD mshlflags, LPCLSID pCid) PURE;
  796.     STDMETHOD(GetMarshalSizeMax)(THIS_ REFIID riid, LPVOID pv, 
  797.                         DWORD dwDestContext, LPVOID pvDestContext,
  798.                         DWORD mshlflags, LPDWORD pSize) PURE;
  799.     STDMETHOD(MarshalInterface)(THIS_ LPSTREAM pStm, REFIID riid,
  800.                         LPVOID pv, DWORD dwDestContext, LPVOID pvDestContext,
  801.                         DWORD mshlflags) PURE;
  802.     STDMETHOD(UnmarshalInterface)(THIS_ LPSTREAM pStm, REFIID riid,
  803.                         LPVOID FAR* ppv) PURE;
  804.     STDMETHOD(ReleaseMarshalData)(THIS_ LPSTREAM pStm) PURE;
  805.     STDMETHOD(DisconnectObject)(THIS_ DWORD dwReserved) PURE;
  806. };
  807. typedef         IMarshal FAR* LPMARSHAL;
  808.  
  809.  
  810. #undef  INTERFACE
  811. #define INTERFACE   IStdMarshalInfo
  812.  
  813. DECLARE_INTERFACE_(IStdMarshalInfo, IUnknown)
  814. {
  815.     // *** IUnknown methods ***
  816.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  817.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  818.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  819.  
  820.     // *** IStdMarshalInfo methods ***
  821.     STDMETHOD(GetClassForHandler)(THIS_ DWORD dwDestContext, 
  822.                         LPVOID pvDestContext, LPCLSID pClsid) PURE;
  823. };
  824. typedef         IStdMarshalInfo FAR* LPSTDMARSHALINFO;
  825.  
  826.  
  827. /****** Message Filter Interface *******************************************/
  828.  
  829.  
  830. #undef  INTERFACE
  831. #define INTERFACE   IMessageFilter
  832.  
  833. DECLARE_INTERFACE_(IMessageFilter, IUnknown)
  834. {
  835.     // *** IUnknown methods ***
  836.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  837.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  838.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  839.  
  840.     // *** IMessageFilter methods ***
  841.     STDMETHOD_(DWORD, HandleInComingCall) (THIS_ DWORD dwCallType,
  842.                                 HTASK htaskCaller, DWORD dwTickCount,
  843.                                 DWORD dwReserved ) PURE;
  844.     STDMETHOD_(DWORD, RetryRejectedCall) (THIS_ 
  845.                                 HTASK htaskCallee, DWORD dwTickCount,
  846.                                 DWORD dwRejectType ) PURE;
  847.     STDMETHOD_(DWORD, MessagePending) (THIS_ 
  848.                                 HTASK htaskCallee, DWORD dwTickCount, 
  849.                                 DWORD dwPendingType  ) PURE; 
  850. };
  851. typedef       IMessageFilter FAR* LPMESSAGEFILTER;
  852.  
  853.  
  854. /****** External Connection Information ***********************************/
  855.  
  856. #undef  INTERFACE
  857. #define INTERFACE   IExternalConnection
  858.  
  859. DECLARE_INTERFACE_(IExternalConnection, IUnknown)
  860. {
  861.     // *** IUnknown methods ***
  862.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  863.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  864.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  865.  
  866.     // *** IExternalConnection methods ***
  867.     STDMETHOD_(DWORD, AddConnection) (THIS_ DWORD extconn, DWORD reserved) PURE;
  868.     STDMETHOD_(DWORD, ReleaseConnection) (THIS_ DWORD extconn, DWORD reserved, BOOL fLastReleaseCloses) PURE;
  869. };
  870. typedef       IExternalConnection FAR* LPEXTERNALCONNECTION;
  871.  
  872.  
  873. /****** Enumerator Interfaces *********************************************/
  874.  
  875. /*
  876.  *  Since we don't use parametrized types, we put in explicit declarations
  877.  *  of the enumerators we need.
  878.  */
  879.  
  880.  
  881. #undef  INTERFACE
  882. #define INTERFACE   IEnumString
  883.  
  884. DECLARE_INTERFACE_(IEnumString, IUnknown)
  885. {
  886.     // *** IUnknown methods ***
  887.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  888.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  889.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  890.  
  891.     // *** IEnumString methods ***
  892.     STDMETHOD(Next) (THIS_ ULONG celt, 
  893.                        LPSTR FAR* rgelt, 
  894.                        ULONG FAR* pceltFetched) PURE;
  895.     STDMETHOD(Skip) (THIS_ ULONG celt) PURE;
  896.     STDMETHOD(Reset) (THIS) PURE;
  897.     STDMETHOD(Clone) (THIS_ IEnumString FAR* FAR* ppenm) PURE;
  898. };
  899. typedef      IEnumString FAR* LPENUMSTRING;
  900.  
  901.  
  902. #undef  INTERFACE
  903. #define INTERFACE   IEnumUnknown
  904.  
  905. DECLARE_INTERFACE_(IEnumUnknown, IUnknown)
  906. {
  907.     // *** IUnknown methods ***
  908.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  909.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  910.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  911.  
  912.     // *** IEnumUnknown methods ***
  913.     STDMETHOD(Next) (THIS_ ULONG celt, LPUNKNOWN FAR* rgelt, ULONG FAR* pceltFetched) PURE;
  914.     STDMETHOD(Skip) (THIS_ ULONG celt) PURE;
  915.     STDMETHOD(Reset) (THIS) PURE;
  916.     STDMETHOD(Clone) (THIS_ IEnumUnknown FAR* FAR* ppenm) PURE;
  917. };
  918. typedef         IEnumUnknown FAR* LPENUMUNKNOWN;
  919.  
  920.  
  921. /****** STD Object API Prototypes *****************************************/
  922.  
  923. STDAPI_(DWORD) CoBuildVersion( VOID );
  924.  
  925. /* init/uninit */
  926.  
  927. STDAPI  CoInitialize(LPMALLOC pMalloc);
  928. STDAPI_(void)  CoUninitialize(void);
  929. STDAPI  CoGetMalloc(DWORD dwMemContext, LPMALLOC FAR* ppMalloc);
  930. STDAPI_(DWORD) CoGetCurrentProcess(void);
  931. STDAPI  CoCreateStandardMalloc(DWORD memctx, IMalloc FAR* FAR* ppMalloc);
  932.  
  933.  
  934. /* register/revoke/get class objects */
  935.  
  936. STDAPI  CoGetClassObject(REFCLSID rclsid, DWORD dwClsContext, LPVOID pvReserved,
  937.                     REFIID riid, LPVOID FAR* ppv);
  938. STDAPI  CoRegisterClassObject(REFCLSID rclsid, LPUNKNOWN pUnk,
  939.                     DWORD dwClsContext, DWORD flags, LPDWORD lpdwRegister);
  940. STDAPI  CoRevokeClassObject(DWORD dwRegister);
  941.  
  942.  
  943. /* marshaling interface pointers */
  944.  
  945. STDAPI CoMarshalInterface(LPSTREAM pStm, REFIID riid, LPUNKNOWN pUnk,
  946.                     DWORD dwDestContext, LPVOID pvDestContext, DWORD mshlflags);
  947. STDAPI CoUnmarshalInterface(LPSTREAM pStm, REFIID riid, LPVOID FAR* ppv);
  948. STDAPI CoMarshalHresult(LPSTREAM pstm, HRESULT hresult);
  949. STDAPI CoUnmarshalHresult(LPSTREAM pstm, HRESULT FAR * phresult);
  950. STDAPI CoReleaseMarshalData(LPSTREAM pStm);
  951. STDAPI CoDisconnectObject(LPUNKNOWN pUnk, DWORD dwReserved);
  952. STDAPI CoLockObjectExternal(LPUNKNOWN pUnk, BOOL fLock, BOOL fLastUnlockReleases);
  953. STDAPI CoGetStandardMarshal(REFIID riid, LPUNKNOWN pUnk, 
  954.                     DWORD dwDestContext, LPVOID pvDestContext, DWORD mshlflags,
  955.                     LPMARSHAL FAR* ppMarshal);
  956.  
  957. STDAPI_(BOOL) CoIsHandlerConnected(LPUNKNOWN pUnk);
  958.  
  959. /* dll loading helpers; keeps track of ref counts and unloads all on exit */
  960.  
  961. STDAPI_(HINSTANCE) CoLoadLibrary(LPSTR lpszLibName, BOOL bAutoFree);
  962. STDAPI_(void) CoFreeLibrary(HINSTANCE hInst);
  963. STDAPI_(void) CoFreeAllLibraries(void);
  964. STDAPI_(void) CoFreeUnusedLibraries(void);
  965.  
  966.  
  967. /* helper for creating instances */
  968.  
  969. STDAPI CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter,
  970.                     DWORD dwClsContext, REFIID riid, LPVOID FAR* ppv);
  971.  
  972.  
  973. /* other helpers */
  974. STDAPI_(BOOL) IsEqualGUID(REFGUID rguid1, REFGUID rguid2);
  975. STDAPI StringFromCLSID(REFCLSID rclsid, LPSTR FAR* lplpsz);
  976. STDAPI CLSIDFromString(LPSTR lpsz, LPCLSID pclsid);
  977. STDAPI StringFromIID(REFIID rclsid, LPSTR FAR* lplpsz);
  978. STDAPI IIDFromString(LPSTR lpsz, LPIID lpiid);
  979. STDAPI_(BOOL) CoIsOle1Class(REFCLSID rclsid);
  980. STDAPI ProgIDFromCLSID (REFCLSID clsid, LPSTR FAR* lplpszProgID);
  981. STDAPI CLSIDFromProgID (LPCSTR lpszProgID, LPCLSID lpclsid);
  982. STDAPI_(int) StringFromGUID2(REFGUID rguid, LPSTR lpsz, int cbMax);
  983.  
  984. STDAPI CoCreateGuid(GUID FAR *pguid);
  985.  
  986. STDAPI_(BOOL) CoFileTimeToDosDateTime(
  987.                  FILETIME FAR* lpFileTime, LPWORD lpDosDate, LPWORD lpDosTime);
  988. STDAPI_(BOOL) CoDosDateTimeToFileTime(
  989.                        WORD nDosDate, WORD nDosTime, FILETIME FAR* lpFileTime);
  990. STDAPI  CoFileTimeNow( FILETIME FAR* lpFileTime );
  991.  
  992.  
  993. STDAPI CoRegisterMessageFilter( LPMESSAGEFILTER lpMessageFilter,
  994.                                 LPMESSAGEFILTER FAR* lplpMessageFilter );
  995.  
  996.  
  997. /* TreatAs APIS */
  998.  
  999. STDAPI CoGetTreatAsClass(REFCLSID clsidOld, LPCLSID pClsidNew);
  1000. STDAPI CoTreatAsClass(REFCLSID clsidOld, REFCLSID clsidNew);
  1001.  
  1002.  
  1003. /* the server dlls must define their DllGetClassObject and DllCanUnloadNow
  1004.  * to match these; the typedefs are located here to ensure all are changed at 
  1005.  * the same time.
  1006.  */
  1007.  
  1008. STDAPI  DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID FAR* ppv);
  1009. #ifdef _MAC
  1010. typedef STDAPICALLTYPE HRESULT (FAR* LPFNGETCLASSOBJECT) (REFCLSID, REFIID, LPVOID FAR*);
  1011. #else
  1012. typedef HRESULT (STDAPICALLTYPE FAR* LPFNGETCLASSOBJECT) (REFCLSID, REFIID, LPVOID FAR*);
  1013. #endif
  1014.  
  1015.  
  1016. STDAPI  DllCanUnloadNow(void);
  1017. #ifdef _MAC
  1018. typedef STDAPICALLTYPE HRESULT (FAR* LPFNCANUNLOADNOW)(void);
  1019. #else
  1020. typedef HRESULT (STDAPICALLTYPE FAR* LPFNCANUNLOADNOW)(void);
  1021. #endif
  1022.  
  1023.  
  1024. /****** Debugging Helpers *************************************************/
  1025.  
  1026. #ifdef _DEBUG
  1027. // writes to the debug port and displays a message box
  1028. STDAPI FnAssert(LPSTR lpstrExpr, LPSTR lpstrMsg, LPSTR lpstrFileName, UINT iLine);
  1029. #endif  //  _DEBUG
  1030.  
  1031. #endif // _COMPOBJ_H_
  1032.